import request from '@/utils/request'

// 获取用户列表
export function getUserList(params = {}) {
  return request({
    url: '/v1/admin/users',
    method: 'GET',
    params
  })
}

// 获取用户详情
export function getUserDetail(id) {
  return request({
    url: `/v1/admin/users/${id}`,
    method: 'GET'
  })
}

// 更新用户信息
export function updateUser(id, data) {
  return request({
    url: `/v1/admin/users/${id}`,
    method: 'PUT',
    data
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: `/v1/admin/users/${id}`,
    method: 'DELETE'
  })
}

// 禁用/启用用户
export function toggleUserStatus(id, isActive) {
  return request({
    url: `/v1/admin/users/${id}`,
    method: 'PATCH',
    data: { is_active: isActive }
  })
}

// 获取用户扩展属性
export function getUserAttributes(userId) {
  return request({
    url: `/v1/admin/users/${userId}/attributes`,
    method: 'GET'
  })
}

// 更新用户扩展属性
export function updateUserAttributes(userId, attributes) {
  return request({
    url: `/v1/admin/users/${userId}/attributes`,
    method: 'PUT',
    data: attributes
  })
}

// 删除用户扩展属性
export function deleteUserAttribute(userId, key) {
  return request({
    url: `/v1/admin/users/${userId}/attributes/${key}`,
    method: 'DELETE'
  })
}

// 搜索用户
export function searchUsers(params) {
  return request({
    url: '/v1/admin/users/search',
    method: 'GET',
    params
  })
}

// 导出用户数据
export function exportUsers(params) {
  return request({
    url: '/v1/admin/users/export',
    method: 'GET',
    params,
    responseType: 'blob'
  })
}

// 用户社交关系管理

// 获取用户关系列表
export function getUserRelations(userId, params = {}) {
  return request({
    url: `/v1/admin/users/${userId}/relations`,
    method: 'GET',
    params
  })
}

// 创建用户关系
export function createUserRelation(data) {
  return request({
    url: '/v1/admin/relations',
    method: 'POST',
    data
  })
}

// 更新用户关系
export function updateUserRelation(relationId, data) {
  return request({
    url: `/v1/admin/relations/${relationId}`,
    method: 'PUT',
    data
  })
}

// 删除用户关系
export function deleteUserRelation(relationId) {
  return request({
    url: `/v1/admin/relations/${relationId}`,
    method: 'DELETE'
  })
}

// 用户活动管理

// 获取用户参与的活动
export function getUserActivities(userId, params = {}) {
  return request({
    url: `/v1/admin/users/${userId}/activities`,
    method: 'GET',
    params
  })
}

// 获取活动详情
export function getActivityDetail(activityId) {
  return request({
    url: `/v1/user/activities/${activityId}`,
    method: 'GET'
  })
}

// 获取活动参与者列表
export function getActivityParticipants(activityId, params = {}) {
  return request({
    url: `/v1/admin/activities/${activityId}/participants`,
    method: 'GET',
    params
  })
}

// 批量删除用户
export function batchDeleteUsers(data) {
  return request({
    url: '/v1/admin/users/batch_delete',
    method: 'POST',
    data
  });
}

export default {
  getUserList,
  getUserDetail,
  updateUser,
  deleteUser,
  toggleUserStatus,
  getUserAttributes,
  updateUserAttributes,
  deleteUserAttribute,
  searchUsers,
  exportUsers,
  getUserRelations,
  createUserRelation,
  updateUserRelation,
  deleteUserRelation,
  getUserActivities,
  getActivityDetail,
  getActivityParticipants,
  batchDeleteUsers
} 